//
//  SINAStuAcitivtyAddPlanViewController.m
//  sinashebao
//
//  Created by  androidlongs on 2018/1/19.
//  Copyright © 2018年  androidlongs. All rights reserved.
// 添加规划

#import "SINAStuAcitivtyAddPlanViewController.h"
#import "SINACircularBeadUtils.h"
#import "SINAStuActiviAddItemTableViewCell.h"
#import "SINAStuActivityAddItemModel.h"
#import "SINAPickDateView.h"
#import "SINAUiviewClickLiserner.h"
#import "SINASchoolModel.h"
#import "SINACalendarUtils.h"
#import "SINACommonPopModel.h"
#import "SINACommonTimePickView.h"
#import "SINASelectLocationViewController.h"
#import "SINACustomScrollView.h"

@interface SINAStuAcitivtyAddPlanViewController ()<UITableViewDelegate,UITableViewDataSource,PickerDateViewDelegate,CommonTimeSelectViewDelegate>
//提交
@property (weak, nonatomic) IBOutlet UIView *commitView;
@property (weak, nonatomic) IBOutlet UITableView *leftTableView;
@property (weak, nonatomic) IBOutlet UITableView *rightTableView;
@property (weak, nonatomic) IBOutlet UIView *seletTimeBackgroundView;

//开始时间
@property (weak, nonatomic) IBOutlet UIView *startTimeView;
@property (weak, nonatomic) IBOutlet UILabel *startTimeLabel;

@property (weak, nonatomic) IBOutlet SINACustomScrollView *mainScrollview;
@property (weak, nonatomic) IBOutlet UIView *mainView;
@property (strong,nonatomic) UIScrollView *classScrollView;
@property (strong,nonatomic) UIView *levelView;


//结束时间
@property (weak, nonatomic) IBOutlet UIView *endTimeView;
@property (weak, nonatomic) IBOutlet UILabel *endTimeLabel;

@property(nonatomic,strong) NSMutableArray *leftDataList;
@property(nonatomic,strong) NSMutableArray *rightDataList;


@property (weak, nonatomic) IBOutlet UIView *locationView;
@property (weak, nonatomic) IBOutlet UILabel *locationLabel;
@property (weak, nonatomic) IBOutlet UITextField *inputAddressTextField;


@property(nonatomic,strong) NSString *selectTimeFlag;

@property(nonatomic,assign) NSInteger startYear;
@property(nonatomic,assign) NSInteger startMonth;
@property(nonatomic,assign) NSInteger startDay;
@property(nonatomic,assign) NSInteger startHour;
@property(nonatomic,assign) NSInteger startMin;

@property(nonatomic,assign) NSInteger endYear;
@property(nonatomic,assign) NSInteger endMonth;
@property(nonatomic,assign) NSInteger endDay;
@property(nonatomic,assign) NSInteger endHour;
@property(nonatomic,assign) NSInteger endMin;

@property(strong,nonatomic) SINAStuActivityAddItemModel *leftSelectActivityModel;
@property(strong,nonatomic) SINAStuActivityAddItemModel *rightSelectActivityModel;


@property(assign,nonatomic) BOOL isShowLevel;
@end

@implementation SINAStuAcitivtyAddPlanViewController

-(NSMutableArray *)leftDataList{
    if (!_leftDataList) {
        _leftDataList = [[NSMutableArray alloc]init];
    }
    return _leftDataList;
}
-(NSMutableArray *)rightDataList{
    if (!_rightDataList) {
        _rightDataList = [[NSMutableArray alloc]init];
    }
    return _rightDataList;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewFunction];
    
    
    self.startDay=0;
    self.startMonth =0;
    self.startYear =0;
    
    self.endDay=0;
    self.endMonth =0;
    self.endYear =0;
    
    
    self.commitView.backgroundColor = baseButtonBackGroundColor;
    
    __weak typeof(self) weakSelf = self;
    [[SINAUiviewClickLiserner alloc]viewClickFunction:self.startTimeView andWithBlick:^(UIView *view) {
        [weakSelf selectStartTime];
    }];
    [[SINAUiviewClickLiserner alloc]viewClickFunction:self.endTimeView andWithBlick:^(UIView *view) {
        [weakSelf selectEndTime];
    }];
    
    
    
    SINAStuActivityAddItemModel *model1 =[[SINAStuActivityAddItemModel alloc]init];
    model1.title=@"运动类";
    [self.leftDataList addObject:model1];
    SINAStuActivityAddItemModel *model2 =[[SINAStuActivityAddItemModel alloc]init];
    model2.title=@"学习类";
    [self.leftDataList addObject:model2];
    SINAStuActivityAddItemModel *model3 =[[SINAStuActivityAddItemModel alloc]init];
    model3.title=@"社交类";
    [self.leftDataList addObject:model3];
    [self.leftDataList removeAllObjects];
    
    for (NSInteger i=0; i<10; i++) {
        SINAStuActivityAddItemModel *model4 =[[SINAStuActivityAddItemModel alloc]init];
        model4.title=@"自习教室看书";
        [self.rightDataList addObject:model4];
    }
    [self.rightDataList removeAllObjects];
    //    SINAStuActivityAddItemModel *model= self.leftDataList[0];
    //    model.isSelect = YES;
    //
    //    SINAStuActivityAddItemModel *rmodel= self.rightDataList[0];
    //    rmodel.isSelect = YES;
    
    //[self.leftTableView reloadData];
    //[self.rightTableView reloadData];
    
    [[SINAUiviewClickLiserner alloc]viewClickFunction:self.commitView andWithBlick:^(UIView *view) {
        [weakSelf commitDataFunction];
    }];
    [[SINAUiviewClickLiserner alloc]viewClickFunction:self.locationView andWithBlick:^(UIView *view) {
        DLog(@"选择地点");
        SINASelectLocationViewController *selectController =[[SINASelectLocationViewController alloc]initWithNibName:@"SINASelectLocationViewController" bundle:nil ];
        selectController.searchName=self.rightSelectActivityModel.itemModel.searchKey;
        [weakSelf.navigationController pushViewController:selectController animated:YES];
    }];
    //注册通知
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateLocationNoticeMsg:)name:@"updateLocation" object:nil];
    
}

- (void)updateLocationNoticeMsg:(NSNotification *)text{
    DLog(@"%@",text.userInfo[@"locationName"]);
    DLog(@"－－－－－接收到通知 updateLocationNoticeMsg ------");
    
    self.locationLabel.text =text.userInfo[@"locationName"];
}
-(void)viewWillAppear:(BOOL)animated{
    [self loadingActivityTypeFunction];
}
-(void) initViewFunction{
    
    
    
    [SINACircularBeadUtils makeCircularBead:20 andView:self.commitView andIsSetBackground:NO];
    
    [SINACircularBeadUtils makeCircularBead:4 andView: self.seletTimeBackgroundView andIsSetBackground:NO];
    
    self.leftTableView.delegate=self;
    self.leftTableView.dataSource=self;
    self.leftTableView.tag=101;
    self.leftTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.leftTableView.backgroundColor=[UIColor colorWithHexString:@"#fafafa"];
    self.leftTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.rightTableView.delegate=self;
    self.rightTableView.dataSource=self;
    self.rightTableView.tag=102;
    self.rightTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.rightTableView.backgroundColor=[UIColor colorWithHexString:@"#fafafa"];
    self.rightTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    UILabel *classLabel = [[UILabel alloc]init];
    classLabel.frame=CGRectMake(12, -4, mainW-12*2, 21);
    classLabel.backgroundColor=[UIColor clearColor];
    classLabel.text=@"类别:";
    classLabel.font=[UIFont systemFontOfSize:15];
    classLabel.textColor=[UIColor colorWithHexString:@"#878787"];
    [self.mainView addSubview:classLabel];
    
    UIScrollView *classScrollView = [[UIScrollView alloc]init];
    classScrollView.frame=CGRectMake(12, CGRectGetMaxY(classLabel.frame)+4, mainW-12*2, 80);
    classScrollView.contentSize=CGSizeMake(mainW*2, 80);
    self.classScrollView = classScrollView;
    [self.mainView addSubview:classScrollView];
    
    
    UILabel *projectLabel = [[UILabel alloc]init];
    projectLabel.frame=CGRectMake(12, CGRectGetMaxY(self.classScrollView.frame)+12, mainW-12*2, 21);
    projectLabel.backgroundColor=[UIColor clearColor];
    projectLabel.text=@"项目:";
    projectLabel.font=[UIFont systemFontOfSize:15];
    projectLabel.textColor=[UIColor colorWithHexString:@"#878787"];
    [self.mainView addSubview:projectLabel];
    
    UILabel *selectProjectLabel = [[UILabel alloc]init];
    selectProjectLabel.frame=CGRectMake(mainW-12-100, CGRectGetMaxY(self.classScrollView.frame)+12, 100, 21);
    selectProjectLabel.backgroundColor=[UIColor clearColor];
    selectProjectLabel.text=@"全部";
    selectProjectLabel.textAlignment=NSTextAlignmentRight;
    selectProjectLabel.font=[UIFont systemFontOfSize:13];
    selectProjectLabel.textColor=baseSelectColor;
    [self.mainView addSubview:selectProjectLabel];
    
    [[SINAUiviewClickLiserner alloc]viewClickFunction:selectProjectLabel andWithBlick:^(UIView *view) {
        if (self.isShowLevel) {
            //隐藏
            self.isShowLevel=NO;
            selectProjectLabel.text=@"全部";
            [self updateLevelFunction];
        } else {
            if (self.rightDataList.count<=9) {
                [YPXToastView showToastViewWithText:@"暂无更多分类项目" andDuration:2 andParentView:self.view];
                return ;
            }
            //显示
            self.isShowLevel=YES;
            selectProjectLabel.text=@"收起";
            [self updateLevelFunction];
        }
        
    }];
    
    
    self.isShowLevel=NO;
    self.mainScrollview.showsVerticalScrollIndicator=NO;
    self.mainScrollview.showsHorizontalScrollIndicator=NO;
    UIView *levelView = [[UIView alloc]init];
    levelView.frame=CGRectMake(0, CGRectGetMaxY(selectProjectLabel.frame)+10, mainW, 150);
    levelView.backgroundColor=[UIColor colorWithHexString:@"#f5f5f5"];
    self.levelView = levelView;
    [self.mainView addSubview:levelView];
    
    
    [self performSelector:@selector(modifyConstant) withObject:nil afterDelay:0.1];//延迟加载,执行
    [SINACircularBeadUtils makeCircularBead:4 andView: self.classScrollView andIsSetBackground:NO];
}
//更新二级分类
-(void)updateLevelFunction{
    [self.levelView removeAllSubviews];
    WeakSelf;
    
    
    if (self.rightDataList.count==0) {
        
        UIView *speedView = [[UIView alloc] init];
        //speedView.backgroundColor = [UIColor colorWithHexString:@"#eeeeee"];
        speedView.backgroundColor =[UIColor colorWithHexString:@"#ececec"];
        speedView.layer.zPosition = 1;  // re
        speedView.frame = CGRectMake(0,0, CGRectGetWidth(self.levelView.frame), CGRectGetHeight(self.levelView.frame));
        speedView.tag=201;
        [self.levelView addSubview:speedView];
        [SINACircularBeadUtils makeCircularBead:4 andView: speedView andIsSetBackground:NO];
        
        
        
        UILabel *titleLabel = [[UILabel alloc]init];
        titleLabel.frame=CGRectMake(0, 0, CGRectGetWidth(speedView.frame), CGRectGetHeight(speedView.frame));
        titleLabel.backgroundColor=[UIColor clearColor];
        titleLabel.text=@"暂无活动项目";
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.font=[UIFont systemFontOfSize:13];
        titleLabel.textColor=[UIColor colorWithHexString:@"#212121"];
        [speedView addSubview:titleLabel];
        
    }else{
    //每个Item宽高
    CGFloat W = (mainW-12-12-10-10)/3;
    CGFloat H = 43;
    //每行列数
    NSInteger rank = 3;
    //每列间距
    CGFloat rankMargin = 10;
    //每行间距
    CGFloat rowMargin = 10;
    //Item索引 ->根据需求改变索引
    NSUInteger index = self.rightDataList.count;
    if (self.isShowLevel) {
        index = self.rightDataList.count;
    } else {
        if (self.rightDataList.count>9) {
            index = 9;
        } else {
            index = self.rightDataList.count;
        }
    }
    self.mainScrollview.contentSize=CGSizeMake(mainW,CGRectGetMaxY(self.commitView.frame)+index/3*H-50);
    
    for (int i = 0 ; i< index; i++) {
        //Item X轴
        CGFloat X = 12+(i % rank) * (W + rankMargin);
        //Item Y轴
        NSUInteger Y = (i / rank) * (H +rowMargin);
        //Item top
        CGFloat top = 0;
        UIView *speedView = [[UIView alloc] init];
        //speedView.backgroundColor = [UIColor colorWithHexString:@"#eeeeee"];
        speedView.backgroundColor =[UIColor redColor];
        speedView.layer.zPosition = 1;  // re
        speedView.frame = CGRectMake(X, Y+top, W, H);
        speedView.tag=201;
        [self.levelView addSubview:speedView];
        [SINACircularBeadUtils makeCircularBead:4 andView: speedView andIsSetBackground:NO];
        
        
        SINAStuActivityAddItemModel *itemmodel = self.rightDataList[i];
        
        if (itemmodel.isSelect) {
            speedView.backgroundColor =[UIColor whiteColor];
        } else {
            speedView.backgroundColor =[UIColor colorWithHexString:@"#ececec"];
        }
        
        UILabel *titleLabel = [[UILabel alloc]init];
        titleLabel.frame=CGRectMake(0, 0, CGRectGetWidth(speedView.frame), CGRectGetHeight(speedView.frame));
        titleLabel.backgroundColor=[UIColor clearColor];
        titleLabel.text=itemmodel.title;
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.font=[UIFont systemFontOfSize:13];
        titleLabel.textColor=[UIColor colorWithHexString:@"#212121"];
        [speedView addSubview:titleLabel];
        
        
        [[SINAUiviewClickLiserner alloc]viewClickFunction:speedView andWithBlick:^(UIView *view) {
            for (NSInteger i=0; i<weakSelf.levelView.subviews.count; i++) {
                UIView *itemView =weakSelf.levelView.subviews[i];
                if (itemView.tag==201) {
                    itemView.backgroundColor=speedView.backgroundColor =[UIColor colorWithHexString:@"#ececec"];
                }
            }
             for (NSInteger i=0; i<self.rightDataList.count; i++) {
                 SINAStuActivityAddItemModel *itemmodel = weakSelf.rightDataList[i];
                 itemmodel.isSelect=NO;
             }
            
            
            speedView.backgroundColor =[UIColor whiteColor];
            itemmodel.isSelect=YES;
            weakSelf.rightSelectActivityModel = itemmodel;
            
            if (self.isShowLevel) {
                [self.rightDataList removeObject:itemmodel];
                [self.rightDataList insertObject:itemmodel atIndex:0];
            }
            if (self.rightDataList.count>9&&self.isShowLevel) {
                 [weakSelf.mainScrollview scrollToBottom];
            }
           
            
            
        }];
        
        
        
        if (i==index-1) {
            //更新
            CGRect preframe = self.levelView.frame;
            preframe.size.height=CGRectGetMaxY(speedView.frame)+12;
            self.commitView.layer.zPosition = 2;
            self.seletTimeBackgroundView.layer.zPosition = 2;
            
            
            [UIView animateWithDuration:0.2 animations:^{
                 self.levelView.frame = preframe;
            } completion:^(BOOL finished) {
                CGRect preTimeframe = self.seletTimeBackgroundView.frame;
                preTimeframe.origin.y=CGRectGetMaxY(self.levelView.frame)+12;
                [UIView animateWithDuration:0.25 animations:^{
                    weakSelf.seletTimeBackgroundView.frame = preTimeframe;
                } completion:^(BOOL finished) {
                    
                }];
                
                CGRect preComitframe = self.commitView.frame;
                preComitframe.origin.y=CGRectGetMaxY(preTimeframe)+40;
                [UIView animateWithDuration:0.3 animations:^{
                    weakSelf.commitView.frame = preComitframe;
                } completion:^(BOOL finished) {
//                     self.mainScrollview.contentSize=CGSizeMake(mainW, CGRectGetMaxY(self.commitView.frame)+40);
//                     weakSelf.commitView.frame = preComitframe;
//                    weakSelf.seletTimeBackgroundView.frame = preTimeframe;
                }];
            }];
            
            
        }
    }
    }
}
//更新一级分类
-(void)updateClassFunction{
    [self.classScrollView removeAllSubviews];
    WeakSelf;
    //110
    NSInteger itemWidth = 110;
    if (self.leftDataList.count<=3) {
        itemWidth=(mainW-12*(self.leftDataList.count+1))/self.leftDataList.count;
    }
    
    for (NSInteger i=0; i<self.leftDataList.count; i++) {
        SINAStuActivityAddItemModel *itemmodel = self.leftDataList[i];
        
        UIView *itemView = [[UIView alloc]init];
        itemView.frame = CGRectMake(i*(itemWidth+12), 0, itemWidth, 80);
        [SINACircularBeadUtils makeCircularBead:4 andView: itemView andIsSetBackground:NO];
        [self.classScrollView addSubview:itemView];
        
        if (i==self.leftDataList.count-1&&self.leftDataList.count>3) {
            self.classScrollView.contentSize=CGSizeMake(CGRectGetMaxX(itemView.frame)+12, 80);
        }else{
             self.classScrollView.contentSize=CGSizeMake(0, 80);
        }
        
        
        UIImageView *backgroundImageView = [[UIImageView alloc]init];
        backgroundImageView.frame=CGRectMake(0,0,CGRectGetWidth(itemView.frame),CGRectGetHeight(itemView.frame));
        [itemView addSubview:backgroundImageView];
        
        
        
        UIImageView *iconImageView = [[UIImageView alloc]init];
        [itemView addSubview:iconImageView];
        
        if ([itemmodel.title isEqualToString:@"学习类"]) {
            iconImageView.image=[UIImage imageNamed:@"act_add_bg_stu_icon"];
            iconImageView.frame=CGRectMake(itemWidth/2-21/2, 80/4+4, 21, 25);
            backgroundImageView.tag=101;
            if (itemmodel.isSelect) {
                backgroundImageView.image=[UIImage imageNamed:@"act_add_bg_stu"];
            } else {
                backgroundImageView.image=[UIImage imageNamed:@"act_add_bg_stu_normal"];
                
            }
        }else  if ([itemmodel.title isEqualToString:@"运动类"]) {
            iconImageView.image=[UIImage imageNamed:@"act_add_bg_sport_icon"];
            iconImageView.frame=CGRectMake(itemWidth/2-27/2, 80/4+4, 27, 24);
            backgroundImageView.tag=102;
            if (itemmodel.isSelect) {
                backgroundImageView.image=[UIImage imageNamed:@"act_add_bg_sport"];
            } else {
                backgroundImageView.image=[UIImage imageNamed:@"act_add_bg_sport_normal"];
            }
        }else  if ([itemmodel.title isEqualToString:@"社交类"]) {
            iconImageView.image=[UIImage imageNamed:@"act_add_bg_use_icon"];
            
            iconImageView.frame=CGRectMake(itemWidth/2-25/2, 80/4+4, 25, 23);
            backgroundImageView.tag=103;
            if (itemmodel.isSelect) {
                backgroundImageView.image=[UIImage imageNamed:@"act_add_bg_use"];
            }else{
                backgroundImageView.image=[UIImage imageNamed:@"act_add_bg_use_normal"];
            }
        }else{
            backgroundImageView.image=nil;
            
            if (itemmodel.isSelect) {
                backgroundImageView.backgroundColor=[UIColor colorWithHexString:@"#aaaaaa"];
            }else{
                backgroundImageView.backgroundColor=[UIColor colorWithHexString:@"#878787"];
            }
        }
        
        
        
        
        UILabel *classNameLabel = [[UILabel alloc]init];
        classNameLabel.frame=CGRectMake(0, CGRectGetMaxY(iconImageView.frame)+8, CGRectGetWidth(itemView.frame), 21);
        classNameLabel.textAlignment=NSTextAlignmentCenter;
        classNameLabel.textColor=[UIColor whiteColor];
        classNameLabel.font=[UIFont systemFontOfSize:14];
        classNameLabel.text=itemmodel.title;
        [itemView addSubview:classNameLabel];
        
        
        [[SINAUiviewClickLiserner alloc]viewClickFunction:itemView andWithBlick:^(UIView *view) {
            
            //重置所有
            for (NSInteger g=0; g<self.classScrollView.subviews.count; g++) {
                UIView *childView = self.classScrollView.subviews[g];
                if ([childView isKindOfClass:[UIView class]]) {
                    for (NSInteger s=0; s<childView.subviews.count; s++) {
                        UIView *childSendView = childView.subviews[s];
                        if ([childSendView isKindOfClass:[UIImageView class]]) {
                            UIImageView *childImageView = (UIImageView*)childSendView;
                            switch (childImageView.tag) {
                                case 101:
                                    childImageView.image=[UIImage imageNamed:@"act_add_bg_stu_normal"];
                                    break;
                                case 102:
                                    childImageView.image=[UIImage imageNamed:@"act_add_bg_sport_normal"];
                                    break;
                                case 103:
                                    childImageView.image=[UIImage imageNamed:@"act_add_bg_use_normal"];
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                }
            }
            
            for (NSInteger i=0; i<self.leftDataList.count; i++) {
                SINAStuActivityAddItemModel *model = self.leftDataList[i];
                model.isSelect=NO;
            }
            
            
            //设置选中
            for (NSInteger g=0; g<itemView.subviews.count; g++) {
                UIView *childView = itemView.subviews[g];
                if ([childView isKindOfClass:[UIImageView class]]) {
                    UIImageView *childImageView = (UIImageView*)childView;
                    itemmodel.isSelect=YES;
                    weakSelf.leftSelectActivityModel = itemmodel;
                    [weakSelf loadingActivityTypeLevelFunction:itemmodel.itemModel.schoolId];
                    switch (childView.tag) {
                        case 101:
                            childImageView.image=[UIImage imageNamed:@"act_add_bg_stu"];
                            break;
                        case 102:
                            childImageView.image=[UIImage imageNamed:@"act_add_bg_sport"];
                            break;
                        case 103:
                            childImageView.image=[UIImage imageNamed:@"act_add_bg_use"];
                            break;
                        default:
                            break;
                    }
                }
            }
            
            
            
        }];
        
        
    }
    
    
}
- (void)modifyConstant
{
    self.mainScrollview.scrollEnabled=YES;
    self.mainScrollview.contentSize=CGSizeMake(mainW, mainH*2);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView.tag==101) {
        return self.leftDataList.count;
    } else {
        return self.rightDataList.count;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    SINAStuActiviAddItemTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SINAStuActiviAddItemTableViewCell"];
    
    if (cell == nil) {
        cell= [[[NSBundle mainBundle]loadNibNamed:@"SINAStuActiviAddItemTableViewCell" owner:nil options:nil] firstObject];
        
    }
    WeakSelf;
    if (tableView.tag==101) {
        SINAStuActivityAddItemModel *model = self.leftDataList[indexPath.row];
        cell.pos=indexPath.row;
        cell.clickBlock = ^(SINAStuActivityAddItemModel *itemModel, NSInteger pos) {
            [weakSelf loadingActivityTypeLevelFunction:itemModel.itemModel.schoolId];
            NSInteger index = pos;
            
            weakSelf.leftSelectActivityModel = itemModel;
            
            if (tableView.tag==101) {
                //左侧点击
                for (NSInteger i=0; i<self.leftDataList.count; i++) {
                    SINAStuActivityAddItemModel *model = self.leftDataList[i];
                    model.isSelect=NO;
                }
                SINAStuActivityAddItemModel *model = self.leftDataList[index];
                model.isSelect =YES;
                [self.leftTableView reloadData];
                
                [self.rightDataList removeAllObjects];
                for (NSInteger i=0; i<10; i++) {
                    SINAStuActivityAddItemModel *model4 =[[SINAStuActivityAddItemModel alloc]init];
                    model4.title=[NSString stringWithFormat:@"%@看书",model.title];
                    [self.rightDataList addObject:model4];
                }
                
                SINAStuActivityAddItemModel *model2= self.rightDataList[0];
                model2.isSelect = YES;
                [self.rightTableView reloadData];
            }
        };
        cell.model = model;
    } else {
        SINAStuActivityAddItemModel *model = self.rightDataList[indexPath.row];
        cell.pos=indexPath.row;
        cell.clickBlock = ^(SINAStuActivityAddItemModel *itemModel, NSInteger pos) {
            weakSelf.rightSelectActivityModel = itemModel;
            //右侧点击
            for (NSInteger i=0; i<self.rightDataList.count; i++) {
                SINAStuActivityAddItemModel *model = self.rightDataList[i];
                model.isSelect=NO;
            }
            
            SINAStuActivityAddItemModel *model = self.rightDataList[pos];
            model.isSelect =YES;
            [self.rightTableView reloadData];
        };
        cell.model = model;
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell ;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 45;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
    
    NSInteger index = indexPath.row;
    
    if (tableView.tag==101) {
        //左侧点击
        for (NSInteger i=0; i<self.leftDataList.count; i++) {
            SINAStuActivityAddItemModel *model = self.leftDataList[i];
            model.isSelect=NO;
        }
        SINAStuActivityAddItemModel *model = self.leftDataList[index];
        model.isSelect =YES;
        [self.leftTableView reloadData];
        
        [self.rightDataList removeAllObjects];
        for (NSInteger i=0; i<10; i++) {
            SINAStuActivityAddItemModel *model4 =[[SINAStuActivityAddItemModel alloc]init];
            model4.title=[NSString stringWithFormat:@"%@看书",model.title];
            [self.rightDataList addObject:model4];
        }
        
        SINAStuActivityAddItemModel *model2= self.rightDataList[0];
        model2.isSelect = YES;
        [self.rightTableView reloadData];
    } else {
        //右侧点击
        for (NSInteger i=0; i<self.rightDataList.count; i++) {
            SINAStuActivityAddItemModel *model = self.rightDataList[i];
            model.isSelect=NO;
        }
        
        SINAStuActivityAddItemModel *model = self.rightDataList[index];
        model.isSelect =YES;
        [self.rightTableView reloadData];
    }
    
    
    //    SINAAskDetailViewController *controller = [[SINAAskDetailViewController alloc]init];
    //    controller.model = model;
    //    [self.navigationController pushViewController:controller animated:YES];
    
}



//选择开始时间
-(void) selectStartTime{
    self.selectTimeFlag = @"START";
    //选择开始时间
    [self selectTime:self.startYear :self.startMonth :self.startDay :self.startHour];
}
//选择结束时间
-(void) selectEndTime{
    self.selectTimeFlag = @"END";
    //选择结束时间
    [self selectTime:self.endYear :self.endMonth :self.endDay :self.endHour];
}
//选择时间
-(void) selectTime:(NSInteger)year :(NSInteger) month :(NSInteger) day  :(NSInteger) hour{
    
    [self.view endEditing:YES];
    
    SINACommonTimePickView *timePickView =[[SINACommonTimePickView alloc]init];
    if ([self.selectTimeFlag isEqualToString:@"END"]) {
        timePickView.titleLabel.text=@"结束时间";
        if (self.endYear!=0) {
            [timePickView comTimePicViewDefaultSelect:timePickView andWithYear:self.endYear andWithMonth:self.endMonth andWithDay:self.endDay andWithHoure:self.endHour andWithMin:self.endMin andWithSec:0];
        }
        
    } else {
        timePickView.titleLabel.text=@"开始时间";
        
        if (self.startYear!=0) {
            [timePickView comTimePicViewDefaultSelect:timePickView andWithYear:self.startYear andWithMonth:self.startMonth andWithDay:self.startDay andWithHoure:self.startHour andWithMin:self.startMin andWithSec:0];
        }
    }
    
    
    timePickView.delegate=self;
    timePickView.currentTimeStyle=YEAER_MAONTH_DAY_HOURE_MIN;
    //    [timePickView comTimePicViewDefaultSelect:timePickView andWithYear:2016 andWithMonth:1 andWithDay:22 andWithHoure:23 andWithMin:23 andWithSec:23];
    [timePickView show];
}

-(void)pickerDateView:(SINAPickDateView *)pickerDateView selectYear:(NSInteger)year selectMonth:(NSInteger)month selectDay:(NSInteger)day selectHours:(NSInteger)hour{
    
}

-(void)pickerDateView:(SINAPickDateView *)pickerDateView selectYear:(NSInteger)year selectMonth:(NSInteger)month selectDay:(NSInteger)day selectHours:(NSInteger)hour selectMins:(NSInteger)min selectSecond:(NSInteger)second{
    
    
}

#pragma - CommonTimeSelectViewDelegate Method
- (void)dismissServiceTimeSelectPickView:(SINACommonTimePickView *)customPickView
{
    
}


-(void)commonTimeSelectPickView:(SINACommonTimePickView *)customPickView andWithYear:(NSString *)year andWithMonth:(NSString *)month andWithDay:(NSString *)day andWithHoure:(NSString *)hour andWithMin:(NSString *)min andWithSec:(NSString *)sec{
    DLog(@"end time select %@年%@月%@日 %@时%@分%@秒",year,month,day,hour,min,sec);
    NSString *monthString =[NSString stringWithFormat:@"%ld",[month integerValue]];
    NSString *dayString =[NSString stringWithFormat:@"%ld",[day integerValue]];
    
    NSString *hourString =[NSString stringWithFormat:@"%ld",[hour integerValue]];
    NSString *minString =[NSString stringWithFormat:@"%ld",[min integerValue]];
    if ([month integerValue]<=9) {
        monthString =[NSString stringWithFormat:@"0%@",monthString];
    } else {
        monthString =[NSString stringWithFormat:@"%@",monthString];
    }
    if ([day integerValue]<=9) {
        dayString =[NSString stringWithFormat:@"0%@",dayString];
    } else {
        dayString =[NSString stringWithFormat:@"%@",dayString];
    }
    
    if ([hour integerValue]<=9) {
        hourString =[NSString stringWithFormat:@"0%@",hourString];
    } else {
        hourString =[NSString stringWithFormat:@"%@",hourString];
    }
    
    if ([min integerValue] <=9) {
        minString =[NSString stringWithFormat:@"0%@",minString];
    } else {
        minString =[NSString stringWithFormat:@"%@",minString];
    }
    if ([self.selectTimeFlag isEqualToString:@"START"]) {
        self.startYear=[year integerValue];
        self.startMonth=[month integerValue];
        self.startDay=[day integerValue];
        
        self.startHour=[hour integerValue];
        self.startMin=[min integerValue];
        
        self.startTimeLabel.text=[NSString stringWithFormat:@"%@-%@-%@-%@:%@",year,monthString,dayString,hourString,minString];
    }else{
        self.endYear=[year integerValue];
        self.endMonth=[month integerValue];
        self.endDay=[day integerValue];
        
        self.endHour=[hour integerValue];
        self.endHour=[min integerValue];
        self.endTimeLabel.text=[NSString stringWithFormat:@"%@-%@-%@-%@:%@",year,monthString,dayString,hourString,minString];
    }
}

#pragma mark - BasePickViewDelegate method
- (void)dismissBasePickView:(SINABasePickView *)customPickView
{
    
}


//加载活动一级类型
-(void) loadingActivityTypeFunction{
   
    [self startLoading];
    //    SINAUserModel *userModel=[[SINACommonUserHelper share]getUserModel];
    WeakSelf;
    [CXAFNHttpRequestUtils httpGetRequest:[NSString stringWithFormat:@"%@%@?pid=15",baseUrl,typeByPidUrl] success:^(id responseData) {
        NSString *code = responseData[@"code"];
        [weakSelf stopLoading];
        if ([code isEqualToString:@"1000"]) {
            NSMutableArray *result = responseData[@"content"];
            if (result!=nil&&result.count>0) {
                [weakSelf.leftDataList removeAllObjects];
                [weakSelf.rightDataList removeAllObjects];
                SINAStuActivityAddItemModel *currentSelectItemmodel=nil;
                
                for (NSInteger i=0; i<result.count; i++) {
                    NSDictionary *dic = result[i];
                    SINASchoolModel *model = [[SINASchoolModel alloc]init];
                    model.schoolName=dic[@"name"];
                    model.schoolId=dic[@"id"];
                    SINAStuActivityAddItemModel *itemmodel =[[SINAStuActivityAddItemModel alloc]init];
                    itemmodel.title=model.schoolName;
                    itemmodel.itemModel = model;
                    if (i==0) {
                        if (self.leftSelectActivityModel==nil) {
                            weakSelf.leftSelectActivityModel = itemmodel;
                            currentSelectItemmodel = itemmodel;
                            itemmodel.isSelect = YES;
                        }
                        
                    }else{
                        itemmodel.isSelect = NO;
                    }
                    if (self.leftSelectActivityModel!=nil) {
                        if ([self.leftSelectActivityModel.title isEqualToString:itemmodel.title]) {
                            itemmodel.isSelect=YES;
                            currentSelectItemmodel=itemmodel;
                        }
                    }
                    [weakSelf.leftDataList addObject:itemmodel];
                }
                
                [weakSelf.leftTableView reloadData];
                [weakSelf updateClassFunction];
                if (currentSelectItemmodel!=nil) {
                    SINASchoolModel *firstModel = currentSelectItemmodel.itemModel;
                    [weakSelf loadingActivityTypeLevelFunction:firstModel.schoolId];
                }else{
                    [weakSelf.rightTableView reloadData];
                }
                
                
                
            }else{
                [YPXToastView showToastViewWithText:@"暂无活动项目" andDuration:2 andParentView:self.view];
            }
            
            
            
        }else{
            [weakSelf.leftDataList removeAllObjects];
            [weakSelf.leftTableView reloadData];
            [weakSelf updateClassFunction];
            NSString *message =responseData[@"message"];
            WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定"
                                                                 cancleBtn:nil];
            [alertView showXLAlertView];
        }
        
    } failure:^(NSError *error, NSInteger errCode) {
        [weakSelf stopLoading];
        [weakSelf.leftDataList removeAllObjects];
        [weakSelf.leftTableView reloadData];
        [weakSelf updateClassFunction];
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"获取数据验证失败" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
    }];
    
}
//加载活动二级类型
-(void) loadingActivityTypeLevelFunction:(NSString *)activityType{
   
    //    SINAUserModel *userModel=[[SINACommonUserHelper share]getUserModel];
    [self startLoading];
    WeakSelf;
    [CXAFNHttpRequestUtils httpGetRequest:[NSString stringWithFormat:@"%@%@?pid=%@",baseUrl,typeByPidUrl,activityType] success:^(id responseData) {
        NSString *code = responseData[@"code"];
        [weakSelf stopLoading];
        if ([code isEqualToString:@"1000"]) {
            NSMutableArray *result = responseData[@"content"];
            if (result!=nil&&result.count>0) {
                [weakSelf.rightDataList removeAllObjects];
                for (NSInteger i=0; i<result.count; i++) {
                    NSDictionary *dic = result[i];
                    SINASchoolModel *model = [[SINASchoolModel alloc]init];
                    model.schoolName=dic[@"name"];
                    model.schoolId=dic[@"id"];
                    model.searchKey = dic[@"searchkey"];
                    SINAStuActivityAddItemModel *itemmodel =[[SINAStuActivityAddItemModel alloc]init];
                    itemmodel.title=model.schoolName;
                    itemmodel.itemModel = model;
                    if (i==0) {
                        if (self.rightSelectActivityModel==nil) {
                            weakSelf.rightSelectActivityModel = itemmodel;
                            itemmodel.isSelect = YES;
                        }
                        
                    }else{
                        itemmodel.isSelect = NO;
                    }
                    if ([weakSelf.rightSelectActivityModel.title isEqualToString: itemmodel.title]) {
                        itemmodel.isSelect=YES;
                    }
                    [weakSelf.rightDataList addObject:itemmodel];
                }
                
                [weakSelf.rightTableView reloadData];
                
                [weakSelf updateLevelFunction];
                
                NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
                [weakSelf.rightTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
            }else{
               
                weakSelf.rightSelectActivityModel =nil;
                [weakSelf.rightDataList removeAllObjects];
                [weakSelf.rightTableView reloadData];
                 [weakSelf updateLevelFunction];
                [YPXToastView showToastViewWithText:@"暂无活动项目" andDuration:2 andParentView:self.view];
            }
            
            
            
        }else{
            weakSelf.rightSelectActivityModel =nil;
            [weakSelf.rightDataList removeAllObjects];
            [weakSelf.rightTableView reloadData];
            NSString *message =responseData[@"message"];
            WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定"
                                                                 cancleBtn:nil];
            [alertView showXLAlertView];
        }
        
    } failure:^(NSError *error, NSInteger errCode) {
        weakSelf.rightSelectActivityModel =nil;
        [weakSelf stopLoading];
        [weakSelf.rightDataList removeAllObjects];
        [weakSelf.rightTableView reloadData];
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"获取数据验证失败" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
    }];
    
}


//提交数据
-(void) commitDataFunction{
    
    if (self.rightSelectActivityModel==nil) {
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"请重新选择活动" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
        return;
    }
    
    
    //开始时间
    NSString *address =self.startTimeLabel.text;
    if (address==nil||address.length<1||[address isEqualToString:@"请选择"]) {
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"请选择开始时间" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
        return;
    }
    
    //结束时间
    NSString *endTime =self.endTimeLabel.text;
    if (endTime==nil||endTime.length<1||[endTime isEqualToString:@"请选择"]) {
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"请选择结束时间" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
        return;
    }
    
    //地点
    NSString *location =self.locationLabel.text;
    //NSString *location =self.inputAddressTextField.text;
    if (location==nil||location.length<1||[location isEqualToString:@"请选择"]) {
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"请输入活动地点" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
        return;
    }
    
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    
    //类型id String type  yyyy-MM-dd HH:mm:ss
    [dict setObject:[NSString stringWithFormat:@"%@",self.rightSelectActivityModel.itemModel.schoolId] forKey:@"type"];
    //开始时间 时分秒格式 String starttime
    NSDateFormatter * df = [[NSDateFormatter alloc] init];
    df.dateFormat = @"yyyy-MM-dd-HH:mm";
    
    
    
    NSString * dateString1 = self.startTimeLabel.text;
    NSDate * date = [df dateFromString:dateString1];
    NSString * askStartTime=[NSString stringWithFormat:@"%llu",[SINACalendarUtils getDateTimeTOMilliSeconds:date]];
    [dict setObject:askStartTime forKey:@"starttime"];
    //结束时间 时分秒格式 String endtime
    
    NSString * dateString2 = self.endTimeLabel.text;
    NSDate * date2 = [df dateFromString:dateString2];
    NSString * askEndTime=[NSString stringWithFormat:@"%llu",[SINACalendarUtils getDateTimeTOMilliSeconds:date2]];
    [dict setObject:askEndTime forKey:@"endtime"];
    //开始时间
    if (address==nil||address.length<1||[address isEqualToString:@"请选择"]) {
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"请选择开始时间" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
        return;
    }
    
    //结束时间
    if (endTime==nil||endTime.length<1||[endTime isEqualToString:@"请选择"]) {
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"请选择结束时间" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
        return;
    }
    
    if ([askStartTime integerValue]<=[[SINACalendarUtils currentTimeStr]integerValue]) {
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"开始时间必须大于当前时间" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
        return;
    }
    
    //时间校验
    if ([askEndTime integerValue]<=[askStartTime integerValue]) {
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"结束时间必须大于开始时间" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
        return;
    }
    
    if ((self.startYear!=self.endYear)||(self.startMonth!=self.endMonth)||(self.startDay!=self.endDay)) {
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"开始时间与结束时间必须在同一天" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
        return;
    }

    [self startLoading];
    //组队地址 String address
    [dict setObject:location forKey:@"address"];
    //自定义添加事项 String content
    //创建组队的用户uuid String organizeuuid
    [dict setObject:[[SINACommonUserHelper share] getUserModel].userUid forKey:@"organizeuuid"];
    
    
    NSMutableDictionary *dict2 = [[NSMutableDictionary alloc]init];
    
    [dict2 setObject:[SINAHttpRequestUtils encodeDicParams:dict] forKey:@"sj"];
    
    WeakSelf;
    [CXAFNHttpRequestUtils httpPostRequest:[NSString stringWithFormat:@"%@%@",baseUrl,userStuHomeAddActivityUrl] withParamters:dict2 success:^(id responseData) {
        
        NSString *code = responseData[@"code"];
        [weakSelf stopLoading];
        if ([code isEqualToString:@"1000"]) {
            WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"提交成功" sureBtn:@"去查看"
                                                                 cancleBtn:nil];
            alertView.resultIndex = ^(NSInteger index) {
                
                //创建通知
                NSNotification *notification =[NSNotification notificationWithName:@"stuActivityAddFindOther" object:nil userInfo:dict];
                // 通过 通知中心 发送 通知
                [[NSNotificationCenter defaultCenter] postNotification:notification];
                
                [weakSelf.navigationController popViewControllerAnimated:YES];
                
            };
            [alertView showXLAlertView];
        }else{
            NSString *message =responseData[@"message"];
            WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:message sureBtn:@"确定"
                                                                 cancleBtn:nil];
            [alertView showXLAlertView];
        }
        
        
        
    } failure:^(NSError *error, NSInteger errCode) {
        DLog(@"加载 失败  %@ ",error.debugDescription);
        [weakSelf stopLoading];
        WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"网络异常" sureBtn:@"确定"
                                                             cancleBtn:nil];
        [alertView showXLAlertView];
    }];
}
@end
